<?php 
	if(!isset($_SESSION)){
		session_start();
	}

	// Clear previous messages.
	if(isset($_SESSION['error'])) session_unregister('error');
	if(isset($_SESSION['success'])) session_unregister('success');
	
	// Get values from the page.
	$user = $_POST['user'];
	$userFullName = $_POST['userFullName'];
	$userAddress = $_POST['userAddress'];
	$userTelephone = $_POST['userTelephone'];
	$userTypeId = $_POST['userTypeId'];
	$status = $_POST['status'];
	
	$userPassword = MD5('123456');
	
	include("../dbconnection.php");
	if(mysql_query("UPDATE users SET userFullName = '$userFullName', userAddress = '$userAddress', userTelephone = '$userTelephone', userTypeId = '$userTypeId', status = '$status'  WHERE userName='$user'")){
		$_SESSION['success'] = 'Update Successfully ';
	}else{
		$_SESSION['error'] = 'Error Occured!';
	}
	if(!empty($userPassword)){
		if(mysql_query("UPDATE users SET userPassword = '$userPassword', loginAttempts = 0 WHERE userName='$user'")){
			$_SESSION['success'] = 'Update Successfully ';
		}else{
			$_SESSION['error'] = 'Error Occured!';
		}
	}if (isset($_POST['checkbox'])) { // if ANY of the options was checked
		if(mysql_query("UPDATE users SET userPassword = '$userPassword' WHERE userName='$user'")){
					$_SESSION['success'] = 'Update Successfully';
		}else{
			$_SESSION['error'] = 'Error Occured!';
		}
  
	}
	
	$_SESSION['page'] = "editUsers.php";
	header('Location: ../../');	
?>